/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-08-17 19:49:11
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-03-12 15:53:54
 * @FilePath: /yt-devops/lib/pages/devices/child_device_list/child_device_list_controller.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:get/get.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/pages/devices/device_list/device_list_model.dart';
import 'package:yt_devops/utils/navigate_utils.dart';

class ChildDeviceListController extends GetxController {
  DeviceListModel? deviceTree;
  List<DeviceListModel> devices = [];

  List<int> subDevicesIdList = [];
  List<String> subDevicesNameList = [];

  @override
  void onInit() {
    super.onInit();
    if (Get.arguments != null) {
      deviceTree = Get.arguments['device'];
      devices = deviceTree?.childDeviceList ?? [];

      for (var element in devices) {
        subDevicesIdList.add(element.deviceId!);
        subDevicesNameList
            .add((element.deviceName ?? element.name ?? '').toString());
      }
    }
  }

  @override
  void onReady() {}

  @override
  void onClose() {}

  toDetail(
    DeviceListModel device,
  ) {
    Log.d('toDetail==' + subDevicesNameList.toString());
    NavigateUtils.toDeviceDetail(device.deviceId!, device.productType!,
        device.name ?? device.deviceName ?? '', device.connectStatus!,
        productId: device.productId,
        subDevicesIdList: subDevicesIdList,
        subDevicesNameList: subDevicesNameList,
        deviceTree: deviceTree);
  }
}
